package com.kingmed.kmss.bpmn.flow.service.custom;

import com.kingmed.kmss.bpmn.flow.service.msg.BpmnMsgServiceImpl;
import com.kingmed.kmss.common.constant.sys.MQBindingConstants;
import com.kingmed.kmss.common.dto.bpmn.ProcessStatusDTO;
import com.kingmed.kmss.common.enums.bpmn.ProcessType;
import com.kingmed.kmss.framework.stream.constant.MQConstants;
import com.kingmed.kmss.framework.stream.mq.producer.MQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 流程状态同步服务-调用各服务同步状态接口以更新业务主表中审批状态
 *
 */
@Component
public class ProcessStatusSyncServiceImpl implements ProcessStatusSyncService {

    @Autowired
    BpmnMsgServiceImpl sysMsg;
    @Autowired
    MQProducer mqProducer;

    /**
     * 调用业务模块接口同步状态信息到业务主表
     *
     * @param businessType
     * @param businessId
     * @param processType
     */
    public void syncProcessStatus(String businessType, String businessId, String bizTitle, Integer status, ProcessType processType, Map<String, Object> paramMap) {
        //策略1：调用业务模块接口

        //策略2：发送MQ消息供业务模块消费
        ProcessStatusDTO processStatus = new ProcessStatusDTO();
        processStatus.setApprovalStatus(status).setBizType(businessType).setBizId(businessId);
        processStatus.setProcessType(processType);
        mqProducer.sendMsg(MQBindingConstants.BPMN_PROCESS_STATUS,
                "审批状态消息", processStatus, MQConstants.MQSender.BPMN);

    }
}
